
import java.util.ArrayList;
import java.util.List;
//计算子网掩码
public class subnetMaskCaculate {
    public List<Integer> Two(Integer num) {
        List list = new ArrayList();
        int num1 = 32 - num;
        String text = "";
        for (int i = 0; i < num; i++) {
            text = text + "1";
        }
        for (int i = 0; i < num1; i++) {
            text = text + "0";
        }
        /**
         * 按照指定长度分割字符串
         * @param inputString    需要切割的源字符串
         * @param length    指定的长度
         * @return
         */
        String inputString = text;
        int length = 8;
        List<String> divList = new ArrayList<String>();
        int remainder = (inputString.length()) % length;

        int number = 4;
        for (int index = 0; index < number; index++) {
            String childStr = inputString.substring(index * length, (index + 1) * length);
            divList.add(childStr);
        }
        for (int i = 0; i < divList.size(); i++) {

            int a = Integer.parseInt(divList.get(i), 2);
            list.add(a);
        }
        return list;
    }

}
